$(function () {

    let form = layui.form

    form.verify({
        oldPwd: [
            /^[\S]{6,15}$/,
            '密码的长度为6-15个字符!'
        ],
        newPwd: function (value) {
            let oldPwd = $('[name="oldPwd"]').val()
            if (value == oldPwd) {
                return '新密码不能与原密码相同'
            }
        },
        rePwd: function (value) {
            let newPwd = $('[name="newPwd"]').val()
            if (value !== newPwd) {
                return '两次密码不一致'
            }
        }
    })

    // 修改密码
    $('#formPwd').on('submit', function (e) {

        e.preventDefault()

        axios({
            method: 'POST',
            url: '/my/updatepwd',
            data: $(this).serialize()
        }).then(function (res) {
            if (res.data.status !== 0) {
                return layui.layer.msg(res.data.message)
            }
            layui.layer.msg('恭喜您,修改成功')
            $('#formPwd')[0].reset()
            setTimeout(() => {
                window.parent.location.href = '/login.html'
            }, 1000);
        })






    })



})